package com.backend.models;

import com.backend.utils.CommonStringUtils;
import com.qiniu.util.StringUtils;
import io.ebean.ExpressionList;
import io.ebean.Finder;
import io.ebean.Model;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Entity
@Table(name = "delivery_address")
@Data
public class DeliveryAddress extends Model {
    @Id
    public Integer id;

    public Integer userId;
    public String name;
    public String mobile;
    public String province;
    public String city;
    public String schoolName;
    public String fullAddress;
    public String postCode;
    public Boolean isDefault = false;
    public Boolean deleted = false;
    public Date lastModifyTime;

    public static Finder<Integer, DeliveryAddress> find = new Finder<>(DeliveryAddress.class);

    public static ExpressionList<DeliveryAddress> search() {
        return DeliveryAddress.find.query().where();
    }

    public Map<String, String> getInfoMap() {
        Map<String, String> resMap = new HashMap<>();
        resMap.put("id",CommonStringUtils.safeString(id));
        resMap.put("user_id", CommonStringUtils.safeString(userId));
        resMap.put("name", CommonStringUtils.safeString(name));
        resMap.put("mobile", CommonStringUtils.safeString(mobile));
        resMap.put("province", CommonStringUtils.safeString(province));
        resMap.put("city", CommonStringUtils.safeString(city));
        resMap.put("school_name", CommonStringUtils.safeString(schoolName));
        resMap.put("full_address", CommonStringUtils.safeString(fullAddress));
        resMap.put("post_code", CommonStringUtils.safeString(postCode));
        resMap.put("is_default", CommonStringUtils.safeString(isDefault));
        return resMap;
    }
}
